﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WordWonderGame.UI
{
    public partial class TuTraLoi : UserControl
    {
        public event EventHandler KickTraLoi;
        public TuTraLoi()
        {
            InitializeComponent();
        }
        
        private bool TraLoiDungRoi;

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (!TraLoiDungRoi)
            {
                this.lbTu.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                lbTu.ForeColor = System.Drawing.Color.Blue;
                panel1.BackColor = System.Drawing.Color.White;
            }
        }

        private void panel1_MouseLeave(object sender, EventArgs e)
        {
            if (!TraLoiDungRoi)
            {
                panel1.BackColor = System.Drawing.Color.Silver;
                this.lbTu.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.lbTu.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))));
            }
        }

        private void lbTu_MouseMove(object sender, MouseEventArgs e)
        {
            if (!TraLoiDungRoi)
            {
                this.lbTu.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                lbTu.ForeColor = System.Drawing.Color.Blue;
                panel1.BackColor = System.Drawing.Color.White;
            }
        }

        private void lbTu_MouseLeave(object sender, EventArgs e)
        {
            if (!TraLoiDungRoi)
            {
                panel1.BackColor = System.Drawing.Color.Silver;
                this.lbTu.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.lbTu.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))));
            }
        }

        public void DungRoi()
        {
            timer1.Stop();
            TraLoiDungRoi = true;
            panel1.BackColor = System.Drawing.Color.Transparent;
            this.lbTu.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lbTu.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))));
            lbDapAn.Text = dapan;
            panel1.Cursor = Cursors.Default;
            
        }
        string dapan;
        public void BindTuLen(string tu,string dapan)
        {
            lbTu.Text = tu;
            this.dapan = dapan;
        }


        private void panel1_Click(object sender, EventArgs e)
        {
            if (!TraLoiDungRoi)
            {
                if (KickTraLoi != null)
                {
                    KickTraLoi(dapan, null);
                }
            }
        }

        private void lbTu_Click(object sender, EventArgs e)
        {
            if (!TraLoiDungRoi)
            {
                if (KickTraLoi != null)
                {
                    KickTraLoi(dapan, null);
                }
            }
        }

        public void XongGame()
        {
            if (!TraLoiDungRoi)
            {
                lbDapAn.Text = dapan;
                lbDapAn.ForeColor = Color.Red;
                TraLoiDungRoi = true;
                panel1.BackColor = System.Drawing.Color.Silver;
                this.lbTu.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.lbTu.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))));

            }
        }

        public void SaiRoi()
        {
            timer1.Stop();
        }
        int bienHinhDem = 0;
        int bienHinh = 5;

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (bienHinhDem == bienHinh)
            {
                bienHinhDem = 0;
                timer1.Stop();
            }
            else
            {
                if (bienHinhDem % 2 == 0)
                {
                    panel1.BackColor = System.Drawing.Color.Silver;
                }
                else
                {
                    panel1.BackColor = System.Drawing.Color.Red;
                }
                bienHinhDem++;

            }
        }

    }
}
